﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClusHal
{
    class Cluster:IComparable 
    {
        List<Action> actions;

        public List<Action> Actions
        {
            get { return actions; }
        }

        private int decisionClass=0;

        public int DecisionClass
        {
            get { return decisionClass; }
            set { decisionClass = value; }
        }

        public Cluster()
        {
            actions = new List<Action>();
        }

        /// <summary>
        /// Oblicza, ile wariantów jest dominowanych przez warianty z tego klastra w stosunku do drugiego
        /// </summary>
        /// <param name="c">Inny klaster</param>
        /// <returns>Liczba dominowanych wariantów</returns>
        public int Dominates(Cluster c)
        {
            int t = 0;

            foreach (Action a in actions)
            {
                foreach (Action b in c.Actions)
                {
                    if (a.isDominating(b))
                    {
                        t++;
                    }
                }
            }

            return t;
        }

        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            if (decisionClass == 0)
            {
                sb.Append("#");
            }
            else
            {
                sb.Append(decisionClass.ToString());
            }
            sb.Append(" (");
            sb.Append(actions.Count.ToString());
            sb.Append("): {");
            

            foreach (Action a in actions)
            {
                sb.Append(a.ToString());
                sb.Append(",");
            }
            sb.Append("}");

            return sb.ToString();
        }

        #region IComparable Members

        public int CompareTo(object obj)
        {
            Cluster comparee=(Cluster)obj;
            if (decisionClass > comparee.DecisionClass)
                return 1;
            else
                return -1;
        }

        #endregion
    }
}